<?php 


namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;
use app\admin\controller\Admin;

/**
* 
*/
class Service extends Admin
{
    /**
     * [index 加载首页]
     */
    public function index()
    {
        $list = db('_service_team_information sti,dj_safety_fee sf')
            ->field('sti.id,sti.project_name,sti.service_team_name,sti.user_num,sti.special_personnel_num,sti.machines_record,sti.labor_subcontract,sti.status,sf.servicefee')
            ->where('sti.project_name='.'sf.project_name')
            ->select();
        //echo db('_service_team_information,dj_safety_fee')->getLastSql();die;
        //var_dump($list);die;
        return view('admin@service/index',[
            'service' => $list
        ]);
    }

    /**
     * [addservice 加载添加劳务页面]
     */
    public function addservice()
    {
        //var_dump($res);die;
        return view('admin@service/addservice');
    }



    /**
     * [doadd 执行添加劳务]
     */
    public function doadd()
    {
        $res = input('param.');
        //var_dump($res);die;
        $result = db('_service_team_information')
                  ->insert($res);

        $select = db('_safety_fee sf,dj_service_team_information sti')
                ->where('sf.project_name='.$res['project_name'])
                ->find();
        //var_dump($select);die;
        if ($select == false) {
            return $this->error('请先为项目添加劳务费用!');
        }

        //var_dump($result);
        //var_dump($user->id);
        if ($result > 0) {
            return $this->success('添加成功!', url('admin/service/index'));
        } else {
            return $this->error('添加失败!');
        }

    }

    /**
     * [del 执行删除劳务]
     */
    public function del()
    {

        $p = input('param.');
        //var_dump($p);exit;
        if(db('_service_team_information')->where('id',$p['id'])->delete()){
            $this->success("删除成功！",url('admin/service/index'));
        }else{
            $this->error("删除失败");
        }
    }



    








}

 ?>